<template>
  <div
    id="taskForce"
    v-loading="loading"
  >
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('ex.taskgroup')"
      @release="release"
      @allRelease="allRelease"
      @transform="transform"
      @upData="upData"
    ></v-tableTitle>
    <v-table
        :page="page"
      :hasEdit="false"
      :pageSize="pageSize"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @upData="getTableData"
      ref="table"
    ></v-table>
    <el-dialog
      :modal="false"
      title=""
      :visible.sync="flag"
      width="30%"
      v-dialogDrag
      :close-on-click-modal="false"
    >
      <el-select
        v-model="value"
        :placeholder="$t('common.select')"
        style="width: 100%;margin-top: 20px;"
      >
        <el-option
          v-for="item in options"
          :key="item.code"
          :label="item.description"
          :value="item.code"
        >
        </el-option>
      </el-select>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="flag = false" :disabled="!this.btnPermNameList.includes('WM06010505')">{{$t('common.cancel')}}</el-button>
        <el-button
          type="primary"
          @click="confirm" :disabled="!this.btnPermNameList.includes('WM06010506')"
        >{{$t('common.confirm')}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";

export default {
  name: "taskForce",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('ex.taskdetailkey'),
          prop: "taskdetailkey",
          input: "input",
        },
        {
          label: this.$t('config.shipper'),
          prop: "storerkey",
          input: "input",
        },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input",
        },
        {
          label: this.$t('outbound.permissiontype'),
          prop: "tasktype",
          input: "select",
          options: this.getOptions("codelkup/TASKTYPE")
        },
        {
            label: this.$t('common.status'),
            prop: "status",
            input: "select",
            options: this.getOptions("codelkup/TMSTATUS")
        },
        {
          label: this.$t('in.priority'),
          prop: "priority",
          input: "select",
          options: this.getOptions("codelkup/PRIORITY"),
        },
        {
          label: this.$t('outbound.fromloc'),
          prop: "fromloc",
          input: "input"
        },
        {
          label: this.$t('config.toLoc'),
          prop: "toloc",
          input: "input"
        },
        {
          label: this.$t('out.wavekey'),
          prop: "wavekey",
          input: "input"
        },
        {
          label: this.$t('out.wavetype'),
          prop: "wavetype",
          input: "select",
          options: this.getOptions("codelkup/RTXWAVETYPE"),
        },
        {
          label: this.$t('config.area'),
          prop: "putawayzone",
          input: "input"
        },
        {
          label: this.$t('app.createName'),
          prop: "addwho",
          input: "input"
        },
        {
          label: this.$t('app.createDate'),
          prop: "adddate",
          input: "date"
        },
        {
          label: this.$t('ex.taskgroup'),
          prop: "rtxtaskgrp",
          input: "input"
        },
        {
          label: this.$t('outbound.user'),
          prop: "userkey",
          input: "input"
        },
        {
          label: this.$t('out.starttime'),
          prop: "starttime",
          input: "date"
        },
        {
          label: this.$t('out.endtime'),
          prop: "endtime",
          input: "date"
        },
        /*{
            label: "操作方式",
            prop: "dotype",
            input: "input"
        },
        {
            label:  this.$t('app.remark'),
            prop: "reasonkey",
            input: "input"
        },*/
        {
          label: this.$t('app.editName'),
          prop: "editwho",
          input: "input"
        },
        {
          label: this.$t('out.editDate'),
          prop: "editdate",
          input: "date"
        },
        {
          label: this.$t('ex.rtxrplot'),
          prop: "rtxrplot",
          input: "input"
        },
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
      flag: false,
      options: this.getOptions("codelkup/PRIORITY"),
      value: ''
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('ex.releaseselected'), disabled: this.deleteStatus, certigier: !this.btnPermNameList.includes('WM06010501'), invalid: "release" },
        { label: this.$t('ex.releaseAllAction'), certigier: !this.btnPermNameList.includes('WM06010502'), invalid: "allRelease" },
        { label: this.$t('ex.transform'), disabled: this.deleteStatus, certigier: !this.btnPermNameList.includes('WM06010503'), invalid: "transform" },
        { label: this.$t('ex.upData'), disabled: this.deleteStatus, certigier: !this.btnPermNameList.includes('WM06010504'), invalid: "upData" },
      ]
    }
  },
  created () {
  },
  methods: {
    //更新优先级 【确认】
    async confirm () {
      try {
        this.loading = true;
        let res = await this.$api.post(`/updatePriority/${this.value}`, this.tableSelectData);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          this.$refs.table.delSelectData(this.tableSelectData);
        
      } catch (e) {
        this.$message.error(e);
      }finally {
        this.flag = false;
        this.loading = false;
      }
    },
    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },
    //释放选择的任务
    async release (data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/releaseSelectedTasks`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }finally {
        this.loading =false;
      }
    },
    //一键释放全部任务
    async allRelease () {
      try {
        this.loading = true;
        let res = await this.$api.post(`/releaseAllTasks`, this.tableSearhData);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        

      } catch (e) {
        this.$message.error(e);
      }finally {
        this.loading = false;
      }
    },
    //转换为纸单
    async transform (data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/transformationTaskdetail`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }finally {
        this.loading = false;
      }
    },
    //更新优先级
    async upData () {
      this.flag = true;
    },
    async getTableData (page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryTaskgroupList/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
  },
  mounted () {
    //权限查询
    ;
    this.wms = this.$store.state.wms;
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = false;
        } else {
          this.deleteStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#taskForce {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
